﻿//-------------------------------------------------------------------------------------------
// <copyright file="AccountConverter.cs" company="Russell Wilkins">
//     Copyright (c) Russell Wilkins 2014. All Rights Reserved.
// </copyright>
// <author>Russell Wilkins</author>
// <license href="license.txt">
//     The use of this software is governed by the Microsoft Public License
//     which is included with this distribution.
// </license>
//-------------------------------------------------------------------------------------------
namespace Ripple.Data.Converters
{
    using Helpers;
    using Providers;
    using System;

    /// <summary>
    /// Class to convert between account dto and entity.
    /// </summary>
    internal static class AccountConverter
    {
        internal static Account ToEntity(this AccountData data, IRippleContext rippleContext)
        {
            if (data == null)
            {
                return null;
            }

            Account account = new Account(rippleContext);
            account.UpdateEntity(data);
            return account;
        }

        internal static void UpdateEntity(this Account entity, AccountData data)
        {
            if (data == null)
            {
                return;
            }

            entity.Id = data.Account;
            entity.PreviousTransactionId = data.PreviousTxnID;
            entity.Balance = data.Balance.ToLong();
            entity.OwnerCount = data.OwnerCount;
            entity.NextTransactionSequenceNumber = data.Sequence;
            entity.Updated = DateTime.Now;
        }
    }
}